#include <bits/stdc++.h>
using namespace std;

int d[100005],v[100005],a[100005],p[100005];


int main()
{
    freopen("detect.in", "r", stdin);
    freopen("detect.out", "w", stdout);

    int T;
    cin >> T;

    for (int t=0; t<T; t++)
    {
        int n,m,L,V;
        cin >> n >> m >> L >> V;
        for (int i=0; i<n; i++)
            cin >> d[i] >> v[i] >> a[i];
        for (int i=0; i<m; i++)
            cin >> p[i];
        int ans =0;
        for (int i=0; i<n; i++)
        {
            if (v[i]>V)
                ans++;
        }
        cout << ans << " " << m-1;
    }

    fclose(stdin);
    fclose(stdout);
    return 0;
}
